import cPickle
from config import parser
from PyQt4 import QtGui, QtCore

class ProgramTree(QtGui.QTreeView):
    def __init__(self, parent=None):
        QtGui.QTreeView.__init__(self, parent)
        
    def updateModel(self):
        self.programsmodel = QtGui.QStandardItemModel() 
        self.setModel(self.programsmodel)
        rootitem = self.programsmodel.invisibleRootItem()
        
        tree = parser.get_tree()
        for (node,(values,config)) in tree.items():
            item = QtGui.QStandardItem(config["docname"])
            rootitem.appendRow(item)
            item.setData(QtCore.QVariant(cPickle.dumps(config)))
            for value in values:
                subitem = QtGui.QStandardItem(value);
                item.appendRow(subitem)
        